package com.zlp.quartz.spring;

import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author: zhulaiping
 * @Date: 2021/10/17 14:56
 */
@Component
public class jobInit {

    @Autowired
    Scheduler scheduler;

    @PostConstruct
    public void excute() throws SchedulerException {
        JobDetail detail = JobBuilder.newJob(SampleJob.class).build();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withSchedule(
                CronScheduleBuilder.cronSchedule("* * * * * ? *"))//每秒执行一次
                .startNow().build();

        scheduler.scheduleJob(detail,trigger);
    }
}
